package com.tanhua.admin.controller;

import com.lych.model.domain.UserInfo;
import com.lych.model.vo.PageResult;
import com.lych.model.vo.VideoVo;
import com.tanhua.admin.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/manage")
public class ManageController {

    @Autowired
    private ManageService manageService;

    /**
     * 用户数据翻页
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = manageService.users(page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 用户基本资料
     * @param userId
     * @return
     */
    @GetMapping("/users/{userId}")
    public ResponseEntity usersUserID(@PathVariable("userId") Long userId){
        UserInfo userInfo = manageService.usersUserID(userId);
        return ResponseEntity.ok(userInfo);
    }

    /**
     * 视频记录翻页
     * @param page
     * @param pagesize
     * @param uid
     * @return
     */
    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 Long uid){
        PageResult pr = manageService.videos(page,pagesize,uid);
        return ResponseEntity.ok(pr);
    }

    /**
     *动态分页
     * @param page
     * @param pagesize
     * @param uid
     * @param state
     * @return
     */
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   Long uid, Integer state){
        PageResult pr = manageService.messages(page,pagesize,uid,state);
        return ResponseEntity.ok(pr);
    }

    /**
     * 用户冻结操作
     * @param map
     * @return
     */
    @PostMapping("/users/freeze")
    public ResponseEntity usersFreeze(@RequestBody Map map){
        Map retMap = manageService.usersFreeze(map);
        return ResponseEntity.ok(retMap);
    }

    /**
     * 用户解冻操作
     * @param map
     * @return
     */
    @PostMapping("/users/unfreeze")
    public ResponseEntity usersUnfreeze(@RequestBody Map map){
        Map retMap = manageService.usersUnfreeze(map);
        return ResponseEntity.ok(map);
    }
}
